const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require(".");
const { status } = require("./enums");

const ReceptionBill = sequelize.define(
  "ReceptionBill",
  {
    id: {
      type: Sequelize.UUID,
      defaultValue: Sequelize.UUIDV4,
      primaryKey: true,
    },
    status: {
      type: DataTypes.ENUM,
      values: status.map((it) => it.value),
      allowNull: false,
      defaultValue: null,
    },
    billNo: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
      unique: true,
    },
    creator: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
    },
    address: {
      type: Sequelize.STRING,
      allowNull: false,
      defaultValue: null,
    },
    receptionFrom: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    receptionTo: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    receptionCat: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
    },
    visitingInstitution: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
    },
    visitorCount: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
    },
    visitingPurpose: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
    },
    accompanyEmployee: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: null,
    },
    importantVisitors: {
      type: DataTypes.JSON,
      allowNull: false,
    },
    visitorVehicles: {
      type: DataTypes.TEXT,
    },
    appVehicle: {
      type: DataTypes.STRING,
    },
    appVisiting: {
      type: DataTypes.STRING,
    },
    appAccommodate: {
      type: DataTypes.STRING,
    },
    appDining: {
      type: DataTypes.STRING,
    },
    appConference: {
      type: DataTypes.STRING,
    },
    appGift: {
      type: DataTypes.STRING,
    },
    appElectronicScreen: {
      type: DataTypes.STRING,
    },
  },
  {
    timestamps: true,
  }
);

(async () => {
  await ReceptionBill.sync({ alter: true }); // Creates the table if it doesn't exist
})();
exports.status = status;
module.exports = ReceptionBill;
